Loop in reverse order.

I'm trying to write a DXL script to search a string containing the Object Number attribute in the objects of a module and replace this string by the Object Identifier.

I use the loop:

for obj in all current Module do {

 


But with this loop the "Object Number" 1.1.1 is found and replaced in the string 1.1.1.2, so when I try to find the string 1.1.1.2 I'm not able to find it.

Can anyone help me to rewrite the loop to go in the reverse order? Thank you in advance.

 


Krogen - Fri Feb 10 07:17:47 EST 2012

Re: Loop in reverse order.
ambes_gt - Fri Feb 10 07:53:51 EST 2012

I don't know how to reverse the loop order, but you could convert your object Number to an string and compare the length using length(string). That should be even more reliable. Imagine Object Nunber "1.2" and "2.1.2" - you would run into the same problem again.

Regards

Stefan

Re: Loop in reverse order.
Krogen - Fri Feb 10 08:56:10 EST 2012

ambes_gt - Fri Feb 10 07:53:51 EST 2012
I don't know how to reverse the loop order, but you could convert your object Number to an string and compare the length using length(string). That should be even more reliable. Imagine Object Nunber "1.2" and "2.1.2" - you would run into the same problem again.

Regards

Stefan

Thank you Stefan,
I compare a string with the Object Number and I don't really know how compare the length of the string can help me.
Example:
Object Number: 1.2 => Length = 3
Requirement: This functionality is explained in 2.1.2.
The string can be found in 2.1.2 with the length = 3 too.

Re: Loop in reverse order.
Mathias Mamsch - Fri Feb 10 10:06:37 EST 2012

Krogen - Fri Feb 10 08:56:10 EST 2012
Thank you Stefan,
I compare a string with the Object Number and I don't really know how compare the length of the string can help me.
Example:
Object Number: 1.2 => Length = 3
Requirement: This functionality is explained in 2.1.2.
The string can be found in 2.1.2 with the length = 3 too.

I guess instead of blindly replacing the object number in your attribute, you could first extract the full object number in that attribute and then compare it to the one you are searching for. You can use a regular expression for that. Note that in DOORS object numbers can also contain '-' for text objects or childs of them.
 

string sSearch = "1.1.1"
string theAttribute = "myAttributeName"
Regexp reNumber = regexp "[-.0-9]+"
 
Object o 
for o in all current Module do {
   string s = o.theAttribute
   if (reNumber s) {
       string sFound = s[match 0]
       print "Found number: " sFound "\n"
       if (sSearch == sFound) { 
             // replace here
       }
   }
}

 


Maybe that helps, regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: Loop in reverse order.
Krogen - Mon Feb 13 08:07:04 EST 2012

Mathias Mamsch - Fri Feb 10 10:06:37 EST 2012

I guess instead of blindly replacing the object number in your attribute, you could first extract the full object number in that attribute and then compare it to the one you are searching for. You can use a regular expression for that. Note that in DOORS object numbers can also contain '-' for text objects or childs of them.
 

string sSearch = "1.1.1"
string theAttribute = "myAttributeName"
Regexp reNumber = regexp "[-.0-9]+"
 
Object o 
for o in all current Module do {
   string s = o.theAttribute
   if (reNumber s) {
       string sFound = s[match 0]
       print "Found number: " sFound "\n"
       if (sSearch == sFound) { 
             // replace here
       }
   }
}

 


Maybe that helps, regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Thank you Mathias

With the Regexp and the Match expresions, I am able to filter the words.

Thank you very much.